#include "widget.h"
#include "ui_widget.h"
#include "wqScene.h"
#include <QHBoxLayout>

Widget::Widget(QWidget *parent) :
    QWidget(parent)
{
    QHBoxLayout* hlay = new QHBoxLayout(this);

	// View
    mpView = new QGraphicsView(this);
    mpView->setCacheMode(QGraphicsView::CacheBackground);
    mpView->setTransformationAnchor(QGraphicsView::AnchorViewCenter);
    mpView->setResizeAnchor(QGraphicsView::AnchorViewCenter);

    mpView->setRenderHint(QPainter::Antialiasing, true);
    mpView->setRenderHint(QPainter::TextAntialiasing, false);

    mpView->setViewportUpdateMode(QGraphicsView::MinimalViewportUpdate);

    mpView->setDragMode(QGraphicsView::RubberBandDrag);
    mpView->setRubberBandSelectionMode(Qt::ContainsItemBoundingRect);

	// Scene
    mpScene1 = new wqScene(1, this);
	mpScene2 = new wqScene(2, this);

	connect(mpScene1, SIGNAL(sig_changeScene(int)), this, SLOT(slot_changeScene(int)));
	connect(mpScene2, SIGNAL(sig_changeScene(int)), this, SLOT(slot_changeScene(int)));

    mpView->setScene(mpScene1);

    hlay->addWidget(mpView);

    showMaximized();
}

Widget::~Widget()
{
    //delete ui;
}

void Widget::slot_changeScene( int idx )
{
	if(idx == 1)
	{
		mpView->setScene(mpScene1);
	}
	else
	{
		mpView->setScene(mpScene2);
	}
}
